package com.wuye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wuye.VO.YiBiaoTypeVo;
import com.wuye.charge.domain.WyCost;
import com.wuye.charge.mapper.WyCostMapper;
import com.wuye.domain.WyYbType;
import com.wuye.mapper.WyYbTypeMapper;
import com.wuye.service.IWyYbTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 仪类类型Service业务层处理
 * 
 * @author jack
 * @date 2024-11-22
 */
@Service
public class WyYbTypeServiceImpl extends ServiceImpl<WyYbTypeMapper, WyYbType> implements IWyYbTypeService
{
    @Autowired
    private WyYbTypeMapper wyYbTypeMapper;

    @Autowired
    private WyCostMapper wyCostMapper;

    /**
     * 查询仪类类型
     * 
     * @param ybTpId 仪类类型主键
     * @return 仪类类型
     */
    @Override
    public YiBiaoTypeVo selectWyYbTypeByYbTpId(Long ybTpId)
    {
        YiBiaoTypeVo yiBiaoTypeVo = new YiBiaoTypeVo();
        WyYbType wyYbType = wyYbTypeMapper.selectWyYbTypeByYbTpId(ybTpId);
        WyCost wyCost = wyCostMapper.selectWyCostByCostId(wyYbType.getCostId());
        BeanUtils.copyProperties(wyYbType, yiBiaoTypeVo);
        yiBiaoTypeVo.setWyCost(wyCost);
        return yiBiaoTypeVo;
    }

    /**
     * 查询仪类类型列表
     * 
     * @param wyYbType 仪类类型
     * @return 仪类类型
     */
    @Override
    public List<WyYbType> selectWyYbTypeList(WyYbType wyYbType)
    {
        return wyYbTypeMapper.selectWyYbTypeList(wyYbType);
    }

    @Override
    public List<YiBiaoTypeVo> selectWyYbTypeList2(WyYbType wyYbType)
    {
        QueryWrapper<WyYbType> wrapper = new QueryWrapper<>();
        if (wyYbType.getYbTpName() != null && wyYbType.getYbTpName() !=""){
            wrapper.like("yb_tp_name", wyYbType.getYbTpName());
        }
        List<WyYbType> wyYbTypes = wyYbTypeMapper.selectList(wrapper);
        ArrayList<YiBiaoTypeVo> yiBiaoTypeVos = new ArrayList<>();
        for (WyYbType type : wyYbTypes){
            YiBiaoTypeVo yiBiaoTypeVo = new YiBiaoTypeVo();
            WyCost wyCost = wyCostMapper.selectWyCostByCostId(type.getCostId());
            BeanUtils.copyProperties(type, yiBiaoTypeVo);
            yiBiaoTypeVo.setWyCost(wyCost);
            yiBiaoTypeVos.add(yiBiaoTypeVo);
        }

        return yiBiaoTypeVos;
    }

    /**
     * 新增仪类类型
     * 
     * @param wyYbType 仪类类型
     * @return 结果
     */
    @Override
    public int insertWyYbType(WyYbType wyYbType)
    {
        return wyYbTypeMapper.insert(wyYbType);
    }

    /**
     * 修改仪类类型
     * 
     * @param wyYbType 仪类类型
     * @return 结果
     */
    @Override
    public int updateWyYbType(WyYbType wyYbType)
    {
        return wyYbTypeMapper.updateWyYbType(wyYbType);
    }

    /**
     * 批量删除仪类类型
     * 
     * @param ybTpIds 需要删除的仪类类型主键
     * @return 结果
     */
    @Override
    public int deleteWyYbTypeByYbTpIds(Long[] ybTpIds)
    {
//       return wyYbTypeMapper.deleteBatchIds(Arrays.asList(ybTpIds));
        return wyYbTypeMapper.deleteWyYbTypeByYbTpIds(ybTpIds);
    }

    /**
     * 删除仪类类型信息
     * 
     * @param ybTpId 仪类类型主键
     * @return 结果
     */
    @Override
    public int deleteWyYbTypeByYbTpId(Long ybTpId)
    {
        return wyYbTypeMapper.deleteWyYbTypeByYbTpId(ybTpId);
    }

    @Override
    public List<WyCost> shoufei() {

        List<WyCost> wyCosts = wyCostMapper.selectWyCostList(null);
        return wyCosts;
    }
}
